package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.service.IEwmsIncinerateHandleService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsIncinerateHandleVo;
import ewms.bo.EwmsIncinerateHandleQueryBo;
import ewms.bo.EwmsIncinerateHandleAddBo;
import ewms.bo.EwmsIncinerateHandleEditBo;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 焚化处置Controller
 *
 * @author zhaoxiaochun
 * @date 2022-02-17
 */
@Api(value = "焚化处置控制器", tags = {"焚化处置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/incinerateHandle")
public class EwmsIncinerateHandleController extends BaseController {

    private final IEwmsIncinerateHandleService iEwmsIncinerateHandleService;

    /**
     * 查询焚化处置列表
     */
    @ApiOperation("查询焚化处置列表")
    @PreAuthorize("@ss.hasPermi('business:incinerateHandle:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsIncinerateHandleVo> list(@Validated EwmsIncinerateHandleQueryBo bo) {
        return iEwmsIncinerateHandleService.selectPageIncinerateHandleList(bo);
    }

    /**
     * 导出焚化处置列表
     */
    @ApiOperation("导出焚化处置列表")
    @PreAuthorize("@ss.hasPermi('business:incinerateHandle:export')")
    @Log(title = "焚化处置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsIncinerateHandleVo> export(@Validated EwmsIncinerateHandleQueryBo bo) {
        List<EwmsIncinerateHandleVo> list = iEwmsIncinerateHandleService.selectIncinerateHandleList(bo);
        ExcelUtil<EwmsIncinerateHandleVo> util = new ExcelUtil<EwmsIncinerateHandleVo>(EwmsIncinerateHandleVo.class);
        return util.exportExcel(list, "焚化处置");
    }

    /**
     * 获取焚化处置详细信息
     */
    @ApiOperation("获取焚化处置详细信息")
    @PreAuthorize("@ss.hasPermi('business:incinerateHandle:query')")
    @GetMapping("/{incinerateHandleId}")
    public AjaxResult<EwmsIncinerateHandleVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("incinerateHandleId") Long incinerateHandleId) {
        return AjaxResult.success(iEwmsIncinerateHandleService.queryById(incinerateHandleId));
    }

    /**
     * 新增焚化处置
     */
    @ApiOperation("新增焚化处置")
    @PreAuthorize("@ss.hasPermi('business:incinerateHandle:add')")
    @Log(title = "焚化处置", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsIncinerateHandleAddBo bo) {
        return toAjax(iEwmsIncinerateHandleService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改焚化处置
     */
    @ApiOperation("修改焚化处置")
    @PreAuthorize("@ss.hasPermi('business:incinerateHandle:edit')")
    @Log(title = "焚化处置", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsIncinerateHandleEditBo bo) {
        return toAjax(iEwmsIncinerateHandleService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除焚化处置
     */
    @ApiOperation("删除焚化处置")
    @PreAuthorize("@ss.hasPermi('business:incinerateHandle:remove')")
    @Log(title = "焚化处置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{incinerateHandleIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] incinerateHandleIds) {
        return toAjax(iEwmsIncinerateHandleService.deleteWithValidByIds(Arrays.asList(incinerateHandleIds), true) ? 1 : 0);
    }
}
